<?php

/**
 * This file is part of the Framework03 PHP framework.
 * @author Walter Tamboer
 * @package Framework03
 */


class FW_Validator_StringLength extends FW_Validator_Abstract
{
    /**
     * @var int The minimum length of the data to validate.
     */
    private $minimumLength;

    /**
     * @var int The maximum length of the data to validate.
     */
    private $maximumLength;

    /**
     * Initializes a new instance of this class.
     * @param int $minimumLength The minimum length of the data to validate.
     * @param int $maximumLength The maximum length of the data to validate.
     */
    public function __construct($minimumLength, $maximumLength)
    {
        $this->minimumLength = $minimumLength;
        $this->maximumLength = $maximumLength;
    }

    /**
     * Validates the given data.
     * @param mixed $data The data that should be validated.
     * @return bool Returns true when the given data is valid; false otherwise.
     */
    public function validate($data)
    {
        $length = strlen($data);

        return ($length >= $this->minimumLength && $length <= $this->maximumLength);
    }
}
